
#include "imageDrawingStrategy.h"
#include "ImageLoading.h"

#include <LDF/VisComponent.h>
#include <string>
#include <windows.h>
#include <GL/gl.h>

imageDrawingStrategy::imageDrawingStrategy(std::string imageLocation): VisComponentStrategy()
{
	imageObject = new ImageLoading();
	imageTex = imageObject->loadImageForTexture(imageLocation.c_str());
}

imageDrawingStrategy::~imageDrawingStrategy()
{
	if(imageObject != NULL) delete imageObject;
}

void imageDrawingStrategy::draw(const std::vector<unsigned long> &selectedIds)
{
	float w2 = component->getWidth() / 2.0f;
	float h2 = component->getHeight() / 2.0f;


	glEnable(GL_TEXTURE_2D);	
		glColor3f(1.0, 1.0, 1.0);
		glBindTexture(GL_TEXTURE_2D, imageTex);
		glBegin(GL_QUADS);
			glTexCoord2f(0,0);
			glVertex3f(-w2,-h2,0);
			glTexCoord2f(1,0);
			glVertex3f(w2,-h2,0);
			glTexCoord2f(1,1);
			glVertex3f(w2,h2,0);
			glTexCoord2f(0,1);
			glVertex3f(-w2, h2,0);
		glEnd();
	glDisable(GL_TEXTURE_2D);
	glFlush();
}


void imageDrawingStrategy::drawForPicking()
{
	float w2 = component->getWidth() / 2.0f;
	float h2 = component->getHeight() / 2.0f;

	// Starting at the lower left corner and going counter-clockwise
	float v0[3], v1[3], v2[3], v3[3];
	v0[0] = -w2; v0[1] = -h2; v0[2] = 0;
	v1[0] = w2; v1[1] = -h2; v1[2] = 0;
	v2[0] = w2; v2[1] = h2; v2[2] = 0;
	v3[0] = -w2; v3[1] = h2; v3[2] = 0;
	
	unsigned char pickingColor[3] = { 0, 0, 0 };
	component->getIdColor(pickingColor);
	glColor3ubv(pickingColor);
	glBegin(GL_QUAD_STRIP);
		glVertex3fv(v0);
		glVertex3fv(v1);
		glVertex3fv(v3);
		glVertex3fv(v2);
	glEnd();

}

